﻿using System;

namespace ZyGame
{
    public class Varable<T>
    {
        private T _value;
        private Action<T> _action;
        public T value
        {
            get => GetValue();
            set => SetValue(value);
        }

        public T GetValue()
        {
            return _value;
        }

        public void SetValue(T value)
        {
            _value = value;
            _action?.Invoke(_value);
        }

        public void Register(Action<T> changed)
        {
            _action += changed;
        }

        public void Unregister(Action<T> changed)
        {
            _action -= changed;
        }
    }

}
